﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KickerTournament.BL.MonsterDYP
{
    class MonsterDypMatchFactory : IMatchFactory
    {
        public List<Match> createMatches(List<Team> roundTeams)
        {
            List<Team> availableTeams = new List<Team>(roundTeams);
            List<Match> createdMatches = new List<Match>();
            int matchCount = roundTeams.Count / 2;
            Random rand = new Random();

            for (int matchIndex = 0; matchIndex < matchCount; matchIndex++)
            {
                int team1Index = rand.Next(roundTeams.Count -1);
                Team team1 = roundTeams[team1Index];
                availableTeams.Remove(team1);

                int team2Index = rand.Next(roundTeams.Count - 1);
                Team team2 = roundTeams[team1Index];
                availableTeams.Remove(team2);

                Match createdMatch = new Match(team1, team2);

                createdMatches.Add(createdMatch);
            }

            return createdMatches;
        }
    }
}
